package com.ruoyi.web.controller.airplane;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.TbTaskDetailLogsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbTaskDetailLogs;
import com.ruoyi.system.service.ITbTaskDetailLogsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务执行日志Controller
 *
 * @author ruoyi
 * @date 2025-08-12
 */
@Api(tags = "任务执行日志")
@RestController
@RequestMapping("/system/taskDetail/logs")
public class TbTaskDetailLogsController extends BaseController {
    @Autowired
    private ITbTaskDetailLogsService tbTaskDetailLogsService;

    /**
     * 查询任务执行日志列表
     */
    //  @PreAuthorize("@ss.hasPermi('system:logs:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(TbTaskDetailLogs tbTaskDetailLogs)
//    {
//        startPage();
//        List<TbTaskDetailLogs> list = tbTaskDetailLogsService.selectTbTaskDetailLogsList(tbTaskDetailLogs);
//        return getDataTable(list);
//    }


    //@PreAuthorize("@ss.hasPermi('system:logs:list')")
    @GetMapping("/list")
    @ApiOperation("查询任务执行日志列表")
    public TableDataInfo list(@RequestParam(required = true) Long taskId,
                              @RequestParam(required = false) String  deviceSn
            ,@RequestParam(required = false) Integer success) {
        startPage();
        List<TbTaskDetailLogsVO> list = tbTaskDetailLogsService.selectTbTaskDetailLogsLis(taskId,deviceSn, success);
        return getDataTable(list);
    }

    /**
     * 导出任务执行日志列表
     */
    //@PreAuthorize("@ss.hasPermi('system:logs:export')")
    @Log(title = "任务执行日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出任务执行日志列表")
    public void export(HttpServletResponse response, TbTaskDetailLogs tbTaskDetailLogs) {
        List<TbTaskDetailLogs> list = tbTaskDetailLogsService.selectTbTaskDetailLogsList(tbTaskDetailLogs);
        ExcelUtil<TbTaskDetailLogs> util = new ExcelUtil<TbTaskDetailLogs>(TbTaskDetailLogs.class);
        util.exportExcel(response, list, "任务执行日志数据");
    }

    /**
     * 获取任务执行日志详细信息
     */
    //  @PreAuthorize("@ss.hasPermi('system:logs:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取任务执行日志详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tbTaskDetailLogsService.selectTbTaskDetailLogsById(id));
    }

    /**
     * 新增任务执行日志
     */
    //  @PreAuthorize("@ss.hasPermi('system:logs:add')")
    @Log(title = "任务执行日志", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增任务执行日志")
    public AjaxResult add(@RequestBody TbTaskDetailLogs tbTaskDetailLogs) {
        return toAjax(tbTaskDetailLogsService.insertTbTaskDetailLogs(tbTaskDetailLogs));
    }

    /**
     * 修改任务执行日志
     */
    // @PreAuthorize("@ss.hasPermi('system:logs:edit')")
    @Log(title = "任务执行日志", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改任务执行日志")
    public AjaxResult edit(@RequestBody TbTaskDetailLogs tbTaskDetailLogs) {
        return toAjax(tbTaskDetailLogsService.updateTbTaskDetailLogs(tbTaskDetailLogs));
    }

    /**
     * 删除任务执行日志
     */
    // @PreAuthorize("@ss.hasPermi('system:logs:remove')")
    @Log(title = "任务执行日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除任务执行日志")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbTaskDetailLogsService.deleteTbTaskDetailLogsByIds(ids));
    }
}
